package com.eleadmin.common.system.controller;

import com.eleadmin.common.core.web.BaseController;
import com.eleadmin.common.system.service.OrderTypeService;
import com.eleadmin.common.system.entity.OrderType;
import com.eleadmin.common.system.param.OrderTypeParam;
import com.eleadmin.common.core.web.ApiResult;
import com.eleadmin.common.core.web.PageResult;
import com.eleadmin.common.core.web.PageParam;
import com.eleadmin.common.core.web.BatchParam;
import com.eleadmin.common.core.annotation.OperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 订单类型表控制器
 *
 * @author EleAdmin
 * @since 2025-04-22 22:55:28
 */
@Api(tags = "订单类型表管理")
@RestController
@RequestMapping("/system/orderType")
public class OrderTypeController extends BaseController {
    @Resource
    private OrderTypeService orderTypeService;


    @OperationLog
    @ApiOperation("分页查询订单类型表")
    @GetMapping("/page")
    public ApiResult<PageResult<OrderType>> page(OrderTypeParam param) {

        return success(orderTypeService.pageRel(param));

    }


    @OperationLog
    @ApiOperation("查询全部订单类型表")
    @GetMapping()
    public ApiResult<List<OrderType>> list() {


        return success(orderTypeService.list());

    }


    @OperationLog
    @ApiOperation("根据id查询订单类型表")
    @GetMapping("/{id}")
    public ApiResult<OrderType> get(@PathVariable("id") Integer id) {
        return success(orderTypeService.getById(id));

    }


    @OperationLog
    @ApiOperation("添加订单类型表")
    @PostMapping()
    public ApiResult<?> save(@RequestBody OrderType orderType) {
        if (orderTypeService.save(orderType)) {
            return success("添加成功");
        }
        return fail("添加失败");
    }


    @OperationLog
    @ApiOperation("修改订单类型表")
    @PutMapping()
    public ApiResult<?> update(@RequestBody OrderType orderType) {
        if (orderTypeService.updateById(orderType)) {
            return success("修改成功");
        }
        return fail("修改失败");
    }


    @OperationLog
    @ApiOperation("删除订单类型表")
    @DeleteMapping("/{id}")
    public ApiResult<?> remove(@PathVariable("id") Integer id) {
        if (orderTypeService.removeById(id)) {
            return success("删除成功");
        }
        return fail("删除失败");
    }


    @OperationLog
    @ApiOperation("批量添加订单类型表")
    @PostMapping("/batch")
    public ApiResult<?> saveBatch(@RequestBody List<OrderType> list) {
        if (orderTypeService.saveBatch(list)) {
            return success("添加成功");
        }
        return fail("添加失败");
    }


    @OperationLog
    @ApiOperation("批量修改订单类型表")
    @PutMapping("/batch")
    public ApiResult<?> removeBatch(@RequestBody BatchParam<OrderType> batchParam) {
        if (batchParam.update(orderTypeService, "id")) {
            return success("修改成功");
        }
        return fail("修改失败");
    }


    @OperationLog
    @ApiOperation("批量删除订单类型表")
    @DeleteMapping("/batch")
    public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
        if (orderTypeService.removeByIds(ids)) {
            return success("删除成功");
        }
        return fail("删除失败");
    }

}
